using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Modules.Abstracts;
using FiltronASP.Models.DAO.Interfaces;
using System.Web.UI.WebControls;
using FiltronASP.Models;
using FiltronASP.Models.DAO;
using FiltronASP.Models.DAO.Filtron;
using FiltronASP.Helpers.CatalogueMenu;
using FiltronASP.Helpers.Translations;

namespace FiltronASP.Modules
{
    public class catalogueChangerFiltron : AbstractModule
    {
        private Page currentPage;

        /// <summary>
        /// Klasa odpowiedzialna za generowanie contentu przez modul.
        /// </summary>
        /// <param name="page">biezaca strona</param>
        /// <returns>content</returns>
        public override string GenerateContent(FiltronASP.Models.Page page)
        {
            this.currentPage = page;
            int languageId = Convert.ToInt32(page.language_id);
            int pageId = page.page_id;
            return this.generateBottomMenu(languageId, pageId) + this.generateInnerContent(page);
        }

        private string generateBottomMenu(int languageId, int pageId) 
        {
            string htmlToReturn = String.Empty;
            string templateName = String.Empty;
            IPageDAO pageDAO = new PageDAO();
            ITemplateDAO templateDAO = new TemplateDAO();
            Page currentPageEntity = pageDAO.FindByPK(pageId);
            templateName = templateDAO.FindByPK(currentPageEntity.template_id).template_name;
            if (!templateName.Equals("tpl_CatalogueMarketChanger"))
            {
                htmlToReturn += "<div id=\"bottomMenu\">";
                htmlToReturn += "   <div class=\"selectMarketMenu\">";
                htmlToReturn += "       <span class=\"changeMarketInfo\">" + translationHelper.getTranslation("_selectMarket", languageId) + "</span>";
                htmlToReturn += "   </div>";
                htmlToReturn += "   <ul class=\"selectCarTypeMenu\">";

                htmlToReturn += CatalogueMenuHelper.generateMenuFiltron(languageId, pageId);

                htmlToReturn += "   </ul>"; //</selectCarTypeMenu>
                htmlToReturn += "<div id=\"selectCarTypeMenuUnder\">";

                htmlToReturn += "</div>"; //</selectCarTypeMenuUnder>
                htmlToReturn += "</div>"; //</bottomMenu>   
            }
            return htmlToReturn;
        }

        private string generateInnerContent(Page page) {
            string htmlToReturn = "";
            htmlToReturn += " <div id=\"contentHolderInner\">";
            htmlToReturn += " <div id=\"ajaxStatementInfo\">" + translationHelper.getTranslation("_selectMarketOnMap", Convert.ToInt32(page.language_id)) + "</div>";

            // map


            string FiltronPassengerLink = String.Empty;
            string WIXPassengerLink = String.Empty;
            int filtronTemplateId = 0;
            int wixTemplateId = 0;

            IPageDAO pageDAO = new PageDAO();
            ITemplateDAO templateDAO = new TemplateDAO();
            Template filtronTemplate = templateDAO.FindByLangAndName(Convert.ToInt32(page.language_id), "tpl_app_passenger_filtron");
            if (filtronTemplate != null)
            {
                filtronTemplateId = filtronTemplate.template_id;
            }
            Template wixTemplate = templateDAO.FindByLangAndName(Convert.ToInt32(page.language_id), "tpl_app_passenger");
            if (wixTemplate != null)
            {
                wixTemplateId = wixTemplate.template_id;
            }

            if ((!(wixTemplateId.Equals(0))) && (!(filtronTemplateId.Equals(0))))
            {
                IQueryable<Page> pagesCollection = pageDAO.FindByLanguageAndTemplateIdAndPublished(Convert.ToInt32(page.language_id), wixTemplateId, true);
                if (pagesCollection != null)
                {
                    foreach (Page singlePage in pagesCollection)
                    {
                        WIXPassengerLink = singlePage.page_link;
                    }
                }

                IQueryable<Page> pagesCollectionFiltron = pageDAO.FindByLanguageAndTemplateIdAndPublished(Convert.ToInt32(page.language_id), filtronTemplateId, true);
                if (pagesCollectionFiltron != null)
                {
                    foreach (Page singlePageFiltron in pagesCollectionFiltron)
                    {
                        FiltronPassengerLink = singlePageFiltron.page_link;
                    }
                }
            } // if eq0

            htmlToReturn += "<div id=\"worldMap\">";
            htmlToReturn += "        <map id=\"selectMarketMap\" name=\"selectMarketMap\">";
            htmlToReturn += "          <area href=\"" + WIXPassengerLink + "#contentHolder" + "\" onmouseout=\"worldMapBgOut();\" onmouseover=\"worldMapBg(1);\" title=\"North America\" shape=\"poly\" coords=\"195,180,206,178,208,172,218,171,224,165,236,165,248,172,272,180,241,182,246,176,223,169,210,187,225,188,223,199,228,209,236,206,238,214,226,213,195,184,183,186,167,176,151,158,140,119,155,92,152,60,137,56,71,75,106,60,100,57,116,47,114,41,149,27,186,32,209,28,244,12,291,7,316,1,428,3,406,32,370,42,354,58,342,49,349,31,328,12,311,20,324,38,316,53,321,91,265,110,237,145,238,158,232,158,225,144,192,151,190,171,195,179\" href=\"\"  alt=\"\" title=\"\" />";
            htmlToReturn += "          <area href=\"" + FiltronPassengerLink + "#contentHolder" + "\" onmouseout=\"worldMapBgOut();\" onmouseover=\"worldMapBg(2);\" title=\"Europe\" shape=\"poly\" coords=\"583,34,575,67,588,89,562,95,561,104,568,113,567,117,543,108,517,111,507,113,502,114,506,123,498,127,493,110,483,124,475,119,482,112,469,103,442,125,424,122,425,105,439,105,444,102,443,93,436,90,421,75,439,60,452,81,466,70,460,51,486,33,508,29,535,34,551,34,567,33\" href=\"\"  alt=\"\" title=\"\" />";
            htmlToReturn += "          <area href=\"" + FiltronPassengerLink + "#contentHolder" + "\" onmouseout=\"worldMapBgOut();\" onmouseover=\"worldMapBg(3);\" title=\"Asia\" shape=\"poly\" coords=\"582,33,577,25,585,20,631,15,650,13,669,23,683,20,702,27,715,22,760,31,787,30,829,40,810,55,799,54,807,67,809,83,789,67,793,55,778,55,753,60,752,72,774,81,773,104,775,83,795,109,798,134,777,141,774,132,756,146,769,196,780,215,773,253,766,269,723,257,694,220,704,198,678,170,657,191,649,211,631,171,611,158,580,190,560,195,533,149,529,141,535,125,502,121,502,114,515,110,543,108,567,116,563,95,589,89,575,66,584,31\" href=\"\"  alt=\"\" title=\"\" />";
            htmlToReturn += "          <area href=\"" + FiltronPassengerLink + "#contentHolder" + "\" onmouseout=\"worldMapBgOut();\" onmouseover=\"worldMapBg(4);\" title=\"Africa\" shape=\"poly\" coords=\"425,222,439,221,452,218,461,222,468,237,479,268,474,287,481,299,484,319,493,341,511,336,530,318,529,312,536,307,536,294,551,283,557,291,561,311,566,311,577,280,576,272,567,283,562,284,560,291,549,282,553,271,544,252,566,227,575,217,579,201,564,203,544,181,525,137,498,135,495,146,473,133,473,126,430,127,401,170,402,180,400,187,407,209,417,219\" href=\"\"  alt=\"\" title=\"\" />";
            htmlToReturn += "        </map>";
            htmlToReturn += "        <div id=\"worldMapBg\">";
            htmlToReturn += "            <img src=\"../../../Content/images/map/worldMapDummy.png\" alt=\"\" usemap=\"#selectMarketMap\" />";
            htmlToReturn += "        </div>";
            htmlToReturn += "    </div>";


            // /map
            
            return htmlToReturn;
        }
    }
}
